$(document).ready(function () {
    	if(sessionStorage['rules']){
    		var rules=JSON.parse(sessionStorage["rules"]);
    		var parentMenu=new Array();
    		//添加一级菜单
    		for (var i = 0; i < rules.length; i++) {
    			if(rules[i].pid==0){
    				parentMenu.push(rules[i]);
    			}
    		}
    		//添加一级菜单的子菜单
    		for (var i = 0; i < rules.length; i++) {
    			if(rules[i].pid!=0){
    				for (var m = 0; m < parentMenu.length; m++) {
    					if(rules[i].pid==parentMenu[m].id){
    						if(!parentMenu[m]['child']){
    							parentMenu[m]['child']=new Array();
    						}
    						parentMenu[m]['child'].push(rules[i]);
    					}
    				}
    			}
    		}
    		//加载dom
    		var $ul=$('.sidebar-menu');
    		for (var i = 0; i < parentMenu.length; i++) {
    			var $li=$('<li></li>');
    			$li.addClass("treeview");
    			$li.append("<a href='/"+parentMenu[i].name+"'><i class='fa fa-dashboard'></i>"+parentMenu[i].title+"<span class='pull-right-container'><i class='fa fa-angle-left pull-right'></i></span></a>");
    			$ul.append($li);
    			var $lichild;
    			if(parentMenu[i].child.length>0){
    				$lichild=$('<ul></ul>');
    				$lichild.addClass("treeview-menu");
    				$lichild.css("display","none");
    				$li.append($lichild);
    			}
    			for (var c = 0; c < parentMenu[i].child.length; c++) { 
    				var $childLi=$("<li></li>");
    				$childLi.append("<a href='/"+parentMenu[i].child[c].name+"'><i class='fa fa-circle-o'></i>"+parentMenu[i].child[c].title+"</a>");
    				$lichild.append($childLi);
    			}
    		}
    		
    		
   	 }else{
   	 	
   	 }
 }); 
   